package com.mine.common.core.utils.datetime;

/**
 * 日期时间类型
 *
 * @author gongming
 * @date 2023/9/8 14:49
 */
public enum DateTimeType {
    /**
     * 年
     */
    YEAR("年", "yyyy", "今年", "%Y"),
    /**
     * 季度[春,夏,秋,冬]
     */
    MONTH("月", "yyyy-MM", "本月", "%Y-%m"),
    /**
     * 7
     */
    WEEK("周", "E", "本周", "%Y-%m-%d"),
    /**
     * 24
     */
    DAY("日", "yyyy-MM-dd", "今日", "%Y-%m-%d"),
    /**
     * 60
     */
    HOUR("时", "yyyy-MM-dd HH", "此时", "%Y-%m-%d %H"),
    /**
     * 60
     */
    MINUTE("分", "yyyy-MM-dd HH:mm", "此刻", "%Y-%m-%d %H:%i"),
    /**
     * 1
     */
    SECOND("秒", "yyyy-MM-dd HH:mm:ss", "现在", "%Y-%m-%d %H:%i:%s");

    private final String name, pastFormat, presentFormat, mysqlDateTimeFormat;

    DateTimeType(String name, String pastFormat, String presentFormat, String mysqlDateTimeFormat) {
        this.name = name;
        this.pastFormat = pastFormat;
        this.presentFormat = presentFormat;
        this.mysqlDateTimeFormat = mysqlDateTimeFormat;
    }

    public String getName() {
        return name;
    }

    public String getPastFormat() {
        return pastFormat;
    }

    public String getPresentFormat() {
        return presentFormat;
    }

    public String getMysqlDateTimeFormat() {
        return mysqlDateTimeFormat;
    }

    /**
     * 包括Now Fit Str
     *
     * @param findFitStr str
     * @return boolean
     */
    public static boolean includeNowFitStr(String findFitStr) {
        for (DateTimeType dateTimeType : values()) {
            if (dateTimeType.getPresentFormat().equals(findFitStr)) {
                return true;
            }
        }

        return false;
    }


    /**
     * 下一个级别类型
     *
     * @param type 当前级别
     * @return {@link DateTimeType}
     */
    public static DateTimeType nextDateTimeType(DateTimeType type) {
        switch (type) {
            case YEAR:
                return DateTimeType.MONTH;
            case MONTH:
            case WEEK:
                return DateTimeType.DAY;
            case DAY:
                return DateTimeType.HOUR;
            case HOUR:
                return DateTimeType.MINUTE;
            case MINUTE:
                return DateTimeType.SECOND;
            default:
                throw new IllegalStateException("Not supported value: " + type);
        }
    }
}
